import { Statement, STATEMENT_KIND, STATEMENT_TAG } from '../statement';
import { CreateBehavior } from './types';

export class CreateSchema extends Statement {
  $kind: STATEMENT_KIND.CREATE_SCHEMA = STATEMENT_KIND.CREATE_SCHEMA;
  $name: string;
  $tag: STATEMENT_TAG.EXECUTABLE = STATEMENT_TAG.EXECUTABLE;
  $behavior?: CreateBehavior;

  static isCreateSchema(object: any): object is CreateSchema {
    return (
      Statement.isStatement(object) &&
      object.$kind === STATEMENT_KIND.CREATE_DATABASE
    );
  }

  constructor(name: string) {
    super();
    this.$name = name;
  }
}

export const CreateSchemaBuilder = (name: string): CreateSchema => {
  return new CreateSchema(name);
};

CreateSchemaBuilder.ifNotExists = function (name: string): CreateSchema {
  const statement = CreateSchemaBuilder(name);
  statement.$behavior = 'CREATE_IF_NOT_EXISTS';
  return statement;
};

// CreateSchemaBuilder.orReplace = function (name: string): CreateSchema {
//   const statement = CreateSchemaBuilder(name);
//   statement.$behavior = 'CREATE_OR_REPLACE';
//   return statement;
// };

export type CreateSchemaBuilder = typeof CreateSchemaBuilder;
